package com.wx.gof.pattern.structural.adapter.mvc;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName AdapterService
 * @Author wx
 * @Description 适配器服务-外观模式/门面模式(外观对象)
 * @Date 2018-12-08-22:17
 */
public class AdapterService {
    List<IAdapterTarget> adapterList = new ArrayList<>();
    {
        adapterList.add(new ComplexControllerAdapter());
        adapterList.add(new SimpleControllerAdapter());
    }
    
    /**
     * @methodName: getAdapter
     * @author: wx
     * @description: 获取具体适配器
     * @param controller
     * @date: 2018/12/8
     * @return: com.wx.gof.pattern.structural.adapter.mvc.IAdapterTarget
     */
    public IAdapterTarget  getAdapter(Object controller){
        for (IAdapterTarget iAdapterTarget : adapterList) {
            if (iAdapterTarget.validation(controller)){
                return iAdapterTarget;
            }
        }
        throw new RuntimeException("无任何匹配适配器");
    }
}
